<template>
	<view class="container">
		<view>
			<u-cell-group>
				<!-- #ifdef MP -->
				<view @tap.stop="mpDisableTip"><u-cell-item title="账户与安全"></u-cell-item></view>
				<!-- #endif -->
				<!-- #ifndef MP -->
				<view @tap.stop="toPage" data-url="/pageSetting/account/index"><u-cell-item title="账户与安全"></u-cell-item></view>
				<!-- #endif -->
				<view @tap.stop="toPage" data-url="/pageUser/address/index"><u-cell-item title="我的收货地址"></u-cell-item></view>
			</u-cell-group>
		</view>
		<view style="margin-top: 20rpx;">
			<u-cell-group>
				<view @tap.stop="toPage" data-url="/pageSetting/remind/index"><u-cell-item title="音效与通知"></u-cell-item></view>
				<view @tap.stop="toPage" data-url="/pageSetting/privacy/index"><u-cell-item title="高级筛选与隐私"></u-cell-item></view>
				<view @tap.stop="toPage" data-url="/pageSetting/common/index"><u-cell-item title="通用"></u-cell-item></view>
			</u-cell-group>
		</view>
		<view style="margin-top: 20rpx;">
			<u-cell-group style="margin-top: 20rpx;">
				<view @tap.stop="toPage" :data-url="'/pageSupport/supplement/report?type=' + complaintTypeEnum.PLATFORM.value + '&id=0'"><u-cell-item title="问题反馈"></u-cell-item></view>
				<view @tap.stop="toPage" data-url="/pageSetting/about/index"><u-cell-item title="关于穗穗"></u-cell-item></view>
				<!-- #ifdef APP-PLUS -->
				<u-cell-item title="版本与更新" @click="update"><u-badge :count="newVersion.ver_out" :absolute="false" :type="newVersion.smeta.need_update ? 'error' : 'primary'"></u-badge></u-cell-item>
				<!-- #endif -->
			</u-cell-group>
		</view>
		<!-- #ifndef MP-WEIXIN -->
		<view class="account-exit" v-if="canExit" @tap="exit">退出账号</view>
		<!-- #endif -->
	</view>
</template>

<script>
import Tools from '@/utils/Tools.js';
import ComplaintTypeEnum from '@/utils/enum/ComplaintType.js';
import { mapState } from 'vuex';
export default {
	data() {
		return {
			canExit: true,
			complaintTypeEnum: ComplaintTypeEnum
		};
	},

	onShow() {
		this.refreshUserInfo();
		console.log(this.device);
	},
	// #ifdef APP-PLUS
	computed: {
		...mapState({
			newVersion: state => state.device.newVersion
		})
	},
	// #endif

	methods: {
		// #ifdef APP-PLUS
		update() {
			const { smeta } = this.newVersion;
			if (smeta.need_update == 1) {
				const upDater = uni.requireNativePlugin('CL-UpDater');
				let options = {
					title: !smeta.is_force ? '强制升级' : '更新',
					con: smeta.brief,
					downUrl: smeta.download,
					hidCancelbtn: !smeta.is_force,
					btnBgColor: '#F85962',
					topImgBg: plus.io.convertLocalFileSystemURL('_www/hybrid') + '/top.png'
				};
				upDater.startUpdate(options);
			}
		},
		// #endif
		// #ifndef MP-WEIXIN
		exit() {
			if (this.canExit) {
				uni.showModal({
					title: '确认退出',
					content: '退出后可能无法收到对方的信息哦！是否退出登录',
					cancelColor: '#ccc',
					confirmText: '退出',
					success: res => {
						if (res.confirm) {
							this.$u.api.logout().then(res => {
								Tools.logout().then(() => {
									this.reLaunch();
								});
							});
						}
					}
				});
			}
		},
		// #endif
		// #ifdef MP
		mpDisableTip() {
			uni.showModal({
				title: '',
				content: '小程序上无法进行该设置，请前往app或wap中设置'
			});
		}
		// #endif
	}
};
</script>

<style lang="scss">
.account-exit {
	height: 90rpx;
	background-color: #fff;
	color: $uni-color-error;
	display: flex;
	justify-content: center;
	align-items: center;
	margin-top: 20rpx;
}
</style>
